#include<stdio.h>

int main()
{
	int sign,year,n,d2=28,key=0;
	scanf("%d %d",&year,&n);
	if((year%4==0&&year%100!=0)||year%400==0)
	{
		d2=29;
	}
	for(sign=1;sign<=12;sign++)
	{
		switch(sign)
		{
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
				{
					if(n<=31) key=1;
					else n-=31;
					break;
				}
			case 4:
			case 6:
			case 9:
			case 11:
				{
					if(n<=30) key=1;
					else n-=30;
					break;
				}
			case 2:
				{
					if(n<=d2) key=1;
					else n-=d2;
					break;
				}
		}
		if(key==1) break;
	}
	printf("%d %d",sign,n);
}
